package com.wm.web.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.interceptor.SessionAware;

import com.wm.bean.City;
import com.wm.bean.Shopkeeper;
import com.wm.bean.User;
import com.wm.comm.Constant;
import com.wm.service.CityService;
import com.wm.service.RestaurantService;
import com.wm.service.ShopkeeperService;
import com.wm.service.UserService;
import com.wm.service.web.PageList;
import com.wm.service.web.Pages;
import com.wm.web.ui.OptionsInt;

public class AdminShopkeeper extends BaseAction{
	private static final Log logger = LogFactory.getLog(AdminShopkeeper.class);
	
	private ShopkeeperService shopkeeperService;
	private RestaurantService restaurantService;

	public ShopkeeperService getShopkeeperService() {
		return shopkeeperService;
	}

	public void setShopkeeperService(ShopkeeperService shopkeeperService) {
		this.shopkeeperService = shopkeeperService;
	}

	public RestaurantService getRestaurantService() {
		return restaurantService;
	}

	public void setRestaurantService(RestaurantService restaurantService) {
		this.restaurantService = restaurantService;
	}

	private List statusList = new ArrayList();

	public List getStatusList() {
		return statusList;
	}

	public void setStatusList(List statusList) {
		this.statusList = statusList;
	}
	
	private void setStatusListtValues(){
		statusList = Constant.USER_STATUS;
	}
	
	private void listInitValues(){
		setStatusListtValues();
	}


	private long id;					//主键ID
	private String userName = "";		//用户名称
	private int status = -1;			//状态  0:未激活 1:激活 2::禁用
	
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}


	private PageList pageList;
	
	public PageList getPageList() {
		return pageList;
	}

	public void setPageList(PageList pageList) {
		this.pageList = pageList;
	}	

	public String execute() {
		try {
			return this.executeMethod(this.getAction());
		} catch (Exception e) {
			logger.error(e);
			return INPUT;
		}
	}

	/**
	 * 初始页
	 */
	public String index(){
		listInitValues();
		Pages pages = new Pages();
		pages.setPage(this.getPage());
		pages.setPerPageNum(Constant.PAGE_NUM);
		if (this.getTotal() > 0) {
			pages.setTotalNum(this.getTotal());
		}
		pages.setFileName("/admin_shopkeeper.action?userName="+this.userName+"&status=" + this.status);
		this.setPageList(this.getShopkeeperService().findShopkeepersByUserNameStatus(this.userName, this.status, "id", 1, pages));
		return SUCCESS;
	}
	
	public String updatstatus(){
		Shopkeeper sk = this.getShopkeeperService().findShopkeeperById(this.id);
		sk.setStatus(this.status);
		this.getShopkeeperService().updateShopkeeper(sk);
		return "index";
	}

}
